<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "set_user_up".
 *
 * @property int $id
 * @property float $vip1 购买
 * @property float $vip2
 * @property float $vip3
 * @property float $vip4
 * @property float $vip2_vip1 直推
 * @property float $vip2_vip2
 * @property float $vip2_vip3
 * @property float $vip2_vip4
 * @property float $vip3_vip1
 * @property float $vip3_vip2
 * @property float $vip3_vip3
 * @property float $vip3_vip4
 * @property float $vip4_vip1
 * @property float $vip4_vip2
 * @property float $vip4_vip3
 * @property float $vip4_vip4
 * @property float $sell_1 销售金额
 * @property float $sell_2
 * @property float $sell_3
 * @property float $sell_4
 * @property float $sell_1_amount 销售奖金
 * @property float $sell_2_amount 销售奖金
 * @property float $sell_3_amount 销售奖金
 * @property float $sell_4_amount 销售奖金
 * @property float $sell_num 不得高于
 * @property float $sell_vip
 */
class SetUserUp extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'set_user_up';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['vip1', 'vip2', 'vip3', 'vip4', 'vip2_vip1', 'vip2_vip2', 'vip2_vip3', 'vip2_vip4', 'vip3_vip1', 'vip3_vip2', 'vip3_vip3', 'vip3_vip4', 'vip4_vip1', 'vip4_vip2', 'vip4_vip3', 'vip4_vip4', 'sell_1', 'sell_2', 'sell_3', 'sell_4', 'sell_1_amount', 'sell_2_amount', 'sell_3_amount', 'sell_4_amount', 'sell_num'], 'number'],
            [['vip2_vip1', 'vip2_vip2', 'vip2_vip3', 'vip2_vip4', 'vip3_vip1', 'vip3_vip2', 'vip3_vip3', 'vip3_vip4', 'vip4_vip1', 'vip4_vip2', 'vip4_vip3', 'vip4_vip4', 'sell_1', 'sell_2', 'sell_3', 'sell_4', 'sell_1_amount', 'sell_2_amount', 'sell_3_amount', 'sell_4_amount', 'sell_vip'], 'required'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'vip1' => 'Vip 1',
            'vip2' => 'Vip 2',
            'vip3' => 'Vip 3',
            'vip4' => 'Vip 4',
            'vip2_vip1' => 'Vip 2 Vip 1',
            'vip2_vip2' => 'Vip 2 Vip 2',
            'vip2_vip3' => 'Vip 2 Vip 3',
            'vip2_vip4' => 'Vip 2 Vip 4',
            'vip3_vip1' => 'Vip 3 Vip 1',
            'vip3_vip2' => 'Vip 3 Vip 2',
            'vip3_vip3' => 'Vip 3 Vip 3',
            'vip3_vip4' => 'Vip 3 Vip 4',
            'vip4_vip1' => 'Vip 4 Vip 1',
            'vip4_vip2' => 'Vip 4 Vip 2',
            'vip4_vip3' => 'Vip 4 Vip 3',
            'vip4_vip4' => 'Vip 4 Vip 4',
            'sell_1' => 'Sell  1',
            'sell_2' => 'Sell  2',
            'sell_3' => 'Sell  3',
            'sell_4' => 'Sell  4',
            'sell_1_amount' => 'Sell  1 Amount',
            'sell_2_amount' => 'Sell  2 Amount',
            'sell_3_amount' => 'Sell  3 Amount',
            'sell_4_amount' => 'Sell  4 Amount',
            'sell_num' => 'Sell Num',
        ];
    }

    public static function getLastOne()
    {
        $model = self::find()
            ->orderBy(['id' => SORT_DESC])
            ->one();

        if (!$model) {
            $model = new self();
        }

        return $model;
    }

    public static function saveData($data)
    {
        $model = self::getLastOne();

        if ($model->load(['SetUserUp' => $data]) && $model->save()) {
            return true;
        }
    }
}
